package com.qf.test7;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test07 implements Runnable {
	private static int tickNum=10;
	private static Lock lock =new ReentrantLock(true);
	
	public void saleTick() {
		String window= Thread.currentThread().getName();

		while(true) {
			try {
				lock.lock();
				if(tickNum>0) {
					System.out.println(window + "售出第:" + tickNum + "张票...");
					tickNum--;

				}else {
					break;
				}
			} finally {
				lock.unlock();
			}

		}
		
	}

	@Override
	public void run() {
		this.saleTick();
		
	}
  

}


